package cn.wit.summit.chwan.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.models.dto.GameInfoDetialV2Bean;
import cn.wit.summit.chwan.ui.activity.ImageCollectionActivity;
import cn.wit.summit.chwan.utils.StringUtils;

/**
 * Created by hezl on 2015/1/5.
 */
public class GameDetailV2RImageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private LayoutInflater layoutInflater;
    private List<GameInfoDetialV2Bean.GameScreenShotBean> images = new ArrayList<>();
    private String gameId;

    public GameDetailV2RImageAdapter(Context context, List<GameInfoDetialV2Bean.GameScreenShotBean> images, String gameId) {
        this.context = context;
        this.images = images;
        this.gameId = gameId;
        this.layoutInflater = LayoutInflater.from(context);
    }

    public List<GameInfoDetialV2Bean.GameScreenShotBean> getItems() {
        return this.images;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(layoutInflater.inflate(R.layout.item_game_detail_v2, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        GameInfoDetialV2Bean.GameScreenShotBean temp = images.get(position);

        ViewHolder viewHolder = (ViewHolder) holder;
        String img = temp.getPic();
        if (!StringUtils.isEmpty(img))
            viewHolder.imageViewHPic.setImageURI(img);
        viewHolder.imageViewTypeNumTv.setText(temp.getCount()+"");
        viewHolder.imageViewTypeNameTv.setText(temp.getTitle());
        viewHolder.imageViewHPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ImageCollectionActivity.class);
                intent.putExtra("gameId", gameId);
                intent.putExtra("position", position);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return images.size();
    }


    private class ViewHolder extends RecyclerView.ViewHolder {
        TextView imageViewTypeNumTv;
        TextView imageViewTypeNameTv;
        SimpleDraweeView imageViewHPic;

        public ViewHolder(View itemView) {
            super(itemView);
            imageViewHPic = itemView.findViewById(R.id.imageViewHPic);
            imageViewTypeNumTv = itemView.findViewById(R.id.imageViewTypeNumTv);
            imageViewTypeNameTv = itemView.findViewById(R.id.imageViewTypeNameTv);
        }
    }
}
